package cc.realxyq.kewei.search.controller;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.rest.RestStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;

/**
 * 一句话描述该类的功能
 *
 * @author : Hankewei
 * @version : v1.0
 * @createTime : [2021/6/23 4:45]
 */
@RestController
public class EsController {

    @Autowired
    RestHighLevelClient restHighLevelClient;

    @GetMapping("/index")
    public  Object hello() throws IOException {
        Map product = new HashMap<>();

        IndexRequest request = new IndexRequest("id").id("20")
                .source("spuName", "华为", "id", 20L);
        request.id("10").source("name", "华为").source("id", 10L);
        request.source("name", "华为").source("id", 40L).source("name", "华为").source("id", 30L).source("name", "华为").source("id", 220L);

        //IntStream.range(0, 1000).forEachOrdered(i -> request.source("name", "apple" + i * 100, "id", i * 10));

        IndexResponse response = restHighLevelClient.index(request, RequestOptions.DEFAULT);
            //System.out.println(response.toString());
            return response;
    }

}
